package edu.wfu.preparedDishes.commodity.controller;

import java.util.Arrays;
import java.util.Map;


import edu.wfu.preparedDishes.common.utils.PageUtils;
import edu.wfu.preparedDishes.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import edu.wfu.preparedDishes.commodity.entity.MerchantEntity;
import edu.wfu.preparedDishes.commodity.service.MerchantService;




/**
 * 商家表;
 *
 * @author hero_miracle
 * @email hero_miracle@gmail.com
 * @date 2023-11-22 13:06:46
 */
@RestController
@RequestMapping("commodity/merchant")
public class MerchantController {


    @Autowired
    private MerchantService merchantService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = merchantService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{merchantId}")
    public R info(@PathVariable("merchantId") String merchantId){
		MerchantEntity merchant = merchantService.getById(merchantId);
        return R.ok().put("merchant", merchant);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody MerchantEntity merchant){
		merchantService.add(merchant);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody MerchantEntity merchant){
		merchantService.updateById(merchant);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] merchantIds){
		merchantService.removeByIds(Arrays.asList(merchantIds));
        return R.ok();
    }

}
